package com.guxingke.gblog.dao.impl;

import java.util.List;

import com.guxingke.gblog.dao.ArticleDao;
import com.guxingke.gblog.dmo.Article;
import com.guxingke.gblog.dto.AboutDto;
import com.guxingke.gblog.dto.ArticleDto;
import com.guxingke.gblog.dto.ArticleLiteDto;
import com.guxingke.gblog.util.PageBean;

public class ArticleDaoImpl extends BaseDao implements ArticleDao {
	private ArticleDao dao = null;

	@Override
	public List<ArticleDto> search(Article article) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		List<ArticleDto> result = dao.search(article);

		end();
		return result;
	}

	@Override
	public List<ArticleDto> pagenation(PageBean pageBean) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		List<ArticleDto> result = dao.pagenation(pageBean);

		end();
		return result;
	}

	@Override
	public List<ArticleLiteDto> getRecentArticles() throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		List<ArticleLiteDto> result = dao.getRecentArticles();

		end();
		return result;
	}

	@Override
	public ArticleDto get(Integer id) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		ArticleDto result = dao.get(id);

		end();
		return result;
	}

	@Override
	public ArticleLiteDto getPre(Integer id) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		ArticleLiteDto result = dao.getPre(id);

		end();
		return result;
	}

	@Override
	public ArticleLiteDto getNext(Integer id) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		ArticleLiteDto result = dao.getNext(id);

		end();
		return result;
	}

	@Override
	public List<ArticleLiteDto> getByCategory(int categoryId) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);
		List<ArticleLiteDto> result = dao.getByCategory(categoryId);

		end();
		return result;
	}

	@Override
	public List<ArticleLiteDto> archive() throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		List<ArticleLiteDto> result = dao.archive();

		end();
		return result;
	}

	@Override
	public AboutDto getAbout() throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		AboutDto result = dao.getAbout();

		end();
		return result;
	}

	@Override
	public void updateAbout(AboutDto about) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		dao.updateAbout(about);

		end();
	}

	@Override
	public void saveAbout(AboutDto about) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		dao.saveAbout(about);

		end();
	}

	@Override
	public void update(Article article) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		dao.update(article);

		end();

	}

	@Override
	public void save(Article article) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		dao.save(article);

		end();
	}

	@Override
	public void delete(Integer id) throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		dao.delete(id);

		end();
	}

	@Override
	public int count() throws Exception {
		begin();
		dao = session.getMapper(ArticleDao.class);

		int result = dao.count();

		end();
		return result;
	}

}
